<template>
  <!-- 建设节点信息 -->
  <div style="height:520px">
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      :formType="value.type"
      :labelWidth="120"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {}
    };
  },
  mounted() {
    console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    //初始化数据
    init(data) {
      this.formValue = {};
      if (data.type === 'edit') {
        this.initForm.forEach(x => {
          x.initialValue = data.row[x.fieldName];
        });
      }
    },
    //搜索数据
    initFormFun() {
      return [
        {
          type: 'DATE',
          label: '协议开工时间',
          fieldName: 'field1',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '',
          placeholder: '请选择',
          style: { width: '100%' },
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'DATE',
          label: '实际开工时间',
          fieldName: 'field2',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '',
          placeholder: '请选择',
          style: { width: '100%' },
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'DATE',
          label: '协议完工时间',
          fieldName: 'field3',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '',
          placeholder: '请选择',
          style: { width: '100%' },
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'SELECT',
          label: '建设状态节点',
          fieldName: 'field5',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('1008'),
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'INPUT',
          label: '总体建设进度',
          fieldName: 'field13',
          initialValue: '',
          unitRender: () => {
            return <el-button slot="append">%</el-button>;
          },
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'DATE',
          label: '实际完工时间',
          fieldName: 'field3',
          style: { width: '100%' },
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: '',
          placeholder: '请选择',
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        }
      ];
    },
    formChangeHandle(val) {
      this.formValue = val;
    }
  }
};
</script>